import React from 'react';
import { Modal } from 'antd';
import { ExclamationCircleFilled } from '@ant-design/icons';
import { cancelCustomer } from '@/api';

const { confirm } = Modal;

interface Props {
  customerOrderId: number
  callback: () => void
}

export default function useCancelCustomer() {
  const onCustomerCancel = ({ customerOrderId, callback = () => { } }: Props) => {
    confirm({
      title: '确认要作废这条客户信息吗?',
      icon: <ExclamationCircleFilled />,
      content: '',
      okText: '确定',
      cancelText: '取消',
      onOk() {
        cancelCustomer({ customerOrderId }).then((data) => {
          callback?.();
        })
          .catch((err) => {
            throw (err)
          });
      },
      onCancel() { },
    });

  }

  return onCustomerCancel;
}